home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / parted / debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-03-16  |  2.5 KB  |  90 lines

  1. /*
  2.     libparted - a library for manipulating disk partitions
  3.     Copyright (C) 1998, 1999, 2000, 2002, 2007 Free Software Foundation, Inc.
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 3 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. #ifndef PED_DEBUG_H_INCLUDED
  20. #define PED_DEBUG_H_INCLUDED
  21.  
  22. #include <stdarg.h>
  23.  
  24. #ifdef DEBUG
  25.  
  26. typedef void (PedDebugHandler) ( const int level, const char* file, int line,
  27.                                  const char* function, const char* msg );
  28.  
  29. extern void ped_debug_set_handler (PedDebugHandler* handler);
  30. extern void ped_debug ( const int level, const char* file, int line,
  31.                         const char* function, const char* msg, ... );
  32.  
  33. extern int ped_assert ( int cond, const char* cond_text,
  34.                     const char* file, int line, const char* function );
  35.  
  36. #if defined(__GNUC__) && !defined(__JSFTRACE__)
  37.  
  38. #define PED_DEBUG(level, ...) \
  39.         ped_debug ( level, __FILE__, __LINE__, __PRETTY_FUNCTION__, \
  40.                     __VA_ARGS__ );
  41.  
  42. #define PED_ASSERT(cond, action)                \
  43.     do {                            \
  44.     if (!ped_assert ( cond,                            \
  45.               #cond,                \
  46.               __FILE__,                \
  47.               __LINE__,                \
  48.               __PRETTY_FUNCTION__ ))        \
  49.     {                            \
  50.         action;                        \
  51.     }                            \
  52.     } while (0)
  53.  
  54. #else /* !__GNUC__ */
  55.  
  56. /* function because variadic macros are C99 */
  57. static void PED_DEBUG (int level, ...)
  58. {
  59.         va_list         va_args;
  60.         
  61.         va_start (va_args, level);
  62.         ped_debug ( level, "unknown file", 0, "unknown function", va_args );
  63.         va_end (va_args);
  64. }
  65.         
  66. #define PED_ASSERT(cond, action)                \
  67.     do {                            \
  68.     if (!ped_assert ( cond,                             \
  69.               #cond,                \
  70.               "unknown",                \
  71.               0,                    \
  72.               "unknown" ))                     \
  73.     {                             \
  74.         action;                        \
  75.     }                            \
  76.     } while (0)
  77.  
  78. #endif /* __GNUC__ */
  79.  
  80. #else /* !DEBUG */
  81.  
  82. #define PED_ASSERT(cond, action)    while (0) {}
  83. #define PED_DEBUG(level, ...)           while (0) {}
  84.  
  85.  
  86. #endif /* DEBUG */
  87.  
  88. #endif /* PED_DEBUG_H_INCLUDED */
  89.  
  90.